// pages/serviceEval/serviceEval.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageRoot: app.globalData.imageRoot,
    fanglist:[],
    value: 0,
    status:5,
    checkboxArr: [
      {
       checked: false,//是否选中
       id: "1",//部门能id
       name: "自定义",
      },
      {checked: false,id: "2",name: "服务有礼",},
      // {checked: false,id: "2",name: "服务有礼",},
      // {checked: false,id: "2",name: "服务有礼",},
      {checked: false,id: "3",name: "专业讲师",},
      {checked: false,id: "5",name: "最佳指导",}
     ],
     hiddenmodalput:true,
     customize:'',
     textArea:'',//输入信息
     submitbtn:true,
     select: [{
      name: '服务有礼',
      index: 0
    }, {
      name: '专业讲师',
      index: 0
    }, {
      name: '最佳指导',
      index: 0
    }],
    Model:false,
    disabled:false
  },
  getUserInfo(event) {
    var that = this;
    var select = that.data.select;
    select.push({name:that.data.customize,index:0});
    this.setData({ Model: false ,select:select, getUserInfo(event) {
            var that = this;
            var select = that.data.select;
            select.push({name:that.data.customize,index:0});
            this.setData({ Model: false ,select:select});
          },
        
          onClose() {
            this.setData({ Model: false });
          },});
  },

  onClose() {
    this.setData({ Model: false });
  },
  choose(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    console.log(index)
    var select = this.data.select;
    if (select[index].index != 1) {
      select[index].index = 1
    } else {
      select[index].index = 0
    }
    that.setData({
      select: select
    })
    console.log(select)
  },
  customize(e) {
    var that = this;
    that.setData({
      customize:e.detail.value
    })
  },
  showModel(e) {
    var that = this;
    that.setData({
      Model:true,
      customize:''
    })
      },
  //标签多选
  // checkbox: function (e) {
  //   var index = e.currentTarget.dataset.index;//获取当前点击的下标
  //   var checkboxArr = this.data.checkboxArr;//选项集合
  //   checkboxArr[index].checked = !checkboxArr[index].checked;//改变当前选中的checked值
  //   this.setData({
  //    checkboxArr: checkboxArr
  //   });
  //  },
  onChange(event) {this.setData({value: event.detail,});},
  //点击弹出
	modalinput(){
		this.setData({hiddenmodalput: !this.data.hiddenmodalput})
	},
  //取消按钮
  cancel: function(){this.setData({hiddenmodalput: true});},
  //确认
  confirm: function(){this.setData({hiddenmodalput: true})},
  //文字评论
  bindTextAreaBlur: function(e) { this.setData({ textArea : e.detail.value })},
  submit(e){
    let that = this;
    let rate = that.data.value;
    let texteare = that.data.textArea;
    var i = e.currentTarget.dataset.status;//订单状态
    let id = that.data.fanglist.id
    let data = {
      rate: rate,
      comment: texteare
    }
    // console.log(data)
    var i = e.currentTarget.dataset.status;
    if(i==8){
      if(!data.rate&&!data.comment){
        wx.showToast({
          title: '你没有填写评价哦',
          icon: 'none',
          duration: 1500
        })
        return false //阻止发起请求
      }
      app.ports.api58({id,data}).then((res)=>{
        console.log(res)
        wx.showToast({
          title: '评价成功',
          icon: 'success',
          duration: 1500
        })
        that.setData({
          disabled:true
        })
      }).catch(()=>{console.error('评价失败！')})
    }else{
      wx.showToast({
        title: '订单还没成功！无法评价',
        icon: 'none',
        duration: 1500
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let time = options.time;
    console.log(options)
    var data  = {pk:options.id}
     getApp().ports.api88({data}).then((res) => {
        var that = this;
        let dataList = res.data; //获取到数据
        console.log(dataList)
        if(res.data.oStage != 3){that.setData({disabled:true})}
        if(dataList.rate&&dataList.comment){
          that.setData({ submitbtn : false})
          that.setData({ value : dataList.rate });//获取评论数据
          that.setData({ texteare : dataList.comment });
        }
        if(res.data.marketer){
          let data = { user_pk : res.data.marketer }
          getApp().ports.api56({data}).then((res)=>{
            // console.log(res.data)
            dataList.img = res.data.avatarUrl
            dataList.name = res.data.nickname;
            dataList.telphone = res.data.phone;
            that.setData({ fanglist: dataList })
          }).catch(()=>{console.error('获取用户信息失败！')})
        }
        // dataList.forEach((item) => {
          dataList.arr = dataList.createTime.split(" ");
          dataList.time = time.substring(0,10);
          if(dataList.marketerJoinTime) dataList.arr1 = dataList.marketerJoinTime.split(" ");
          if(dataList.auctionBeforeTime) dataList.arr2 = dataList.auctionBeforeTime.split(" ");
          if(dataList.auctioningTime) dataList.arr3 = dataList.auctioningTime.split(" ");
          if(dataList.auctionDealTime) dataList.arr4 = dataList.auctionDealTime.split(" ");
          if(dataList.auctionAfterTime) dataList.arr5 = dataList.auctionAfterTime.split(" ");
          if(dataList.serviceFinishTime) dataList.arr6 = dataList.serviceFinishTime.split(" ");
          if(dataList.defeatTime) dataList.arr7 = dataList.defeatTime.split(" "); //失败时间
          // dataList.arr5 = dataList.auctionAfterTime.split(" ")||"";
          // dataList.arr6 = dataList.serviceFinishTime.split(" ")||"";
          // dataList.arr7 = dataList.defeatTime.split(" ")||"";
          // dataList.createTime1 = dataList.createTime.substring(0, 5); //要截取时间的字符串
        // })
        dataList.discountHouse.banner = that.data.imageRoot + dataList.discountHouse.banner
        that.setData({ fanglist: dataList })
        // this.setData({ fanglist : res })
      }).catch((error) => {
        console.error(error);
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})